var app = getApp();
var config = require('../../../config.js');
var util = require('../../../js/common.util.js');
Page({
  data: {
    id:'',
    detailInfo:{}
  },
  onLoad: function (options) {
    this.loadDetail(options.id)
    this.setData({
      id:options.id
    })
  },
  onShareAppMessage: function () {

  },
  loadDetail(id){
    let self = this
    app.request({
      url: 'api/wechat/GetBusinessById',
      method: "GET",
      data: {
        id:id
      },
      success: function (res) {
        console.log(res)
        if(res != null &&res.data != null && res.data.info != null){
          res.data.info.createTime = util.formatTime(res.data.info.createTime)

          var strs = res.data.info.productImg
          var imgList = ''
          var img = ''
          if (strs != null && strs != '') {
            imgList = strs.split(',')
            if (imgList != null && imgList.length > 0) {
              img = imgList[0]
            }
          }
          res.data.info.productImg = config.imgPath + img
          console.log(res.data.info.productImg)

          self.setData({
            detailInfo:res.data.info,
          })
        }
      }
    })
  },
  Revoke(){
    let self = this
    wx.showModal({
      title: '提示',
      content: '确定要撤销吗？',
      success: function (sm) {
        if (sm.confirm) {
          app.request({
            url: 'api/wechat/Revoke',
            method: "GET",
            data: {
              id: self.data.id
            },
            success: function (res) {
              wx.showModal({
                showCancel: false,
                content: '已撤销！',
                success: (res) => {
                  wx.switchTab({
                    url: '/page/BusinessCenter/index',
                  })
                },
              })
            }
          })
        } else if (sm.cancel) {
        }
      }
    })
  }
})